<template>
	<view>
		<uni-nav-bar title="账号与安全" left-icon="back" @clickLeft="$tab.back()" :border="false" :fixed="true"
			:statusBar="true"></uni-nav-bar>

		<view class="bg-FFF px-32 py-32 mt-16">
			<view class="text-28 flex items-center justify-between" @click="$tab.nav('/pages/forgetPassword?type=1')">
				<view class="">
					修改密码
				</view>
				<u-icon name="arrow-right" color="#000"></u-icon>
			</view>
			<u-divider></u-divider>
			<view class="text-28 flex items-center justify-between mt-24"
				@click="$tab.nav('/pages/forgetPassword?type=0')">
				<view class="">
					设置支付密码
				</view>
				<u-icon name="arrow-right" color="#000"></u-icon>
			</view>
			<u-divider></u-divider>
			<view class="text-28 flex items-center justify-between mt-24" @click="bandAli">
				<view class="">
					支付宝
				</view>
				<view class="flex items-center" v-if="userInfo.zfbOpenId">
					<view class="">
						{{userInfo.zfbNickName}}
					</view>
					<image :src="userInfo.zfbAvatar" class="image-40 round ml-12" mode=""></image>
				</view>
				<u-icon name="arrow-right" color="#000" v-else></u-icon>
			</view>
			<u-divider></u-divider>
			<view class="text-28 flex items-center justify-between mt-24" @click="handleLogout">
				<view class="">
					账号注销
				</view>
				<u-icon name="arrow-right" color="#000"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				superUser: null,
				userInfo:null
			};
		},
		onLoad() {
			this.userInfo = this.$store.getters.userInfo
		},
		onShow() {
			// #ifdef APP
			let args = plus.runtime.arguments;
			if (args.split("=")[1]) {
				plus.runtime.arguments = null;
				var authCode = args.split("=")[1];
				this.$Api.index.zfbAccount({
					code: authCode
				}).then(bandAli => {
					this.$store.dispatch('GetInfo').then(res=>{
						this.userInfo = res.data
					})
				})
			}
			// #endif
		},
		methods: {
			handleLogout() {
				this.$modal.confirm('确认注销账号并清空相关数据吗?').then(async con => {
					if (con) {
						const res = await this.$Api.user.logOff()
						this.$store.dispatch('LogOut').then(() => {
							this.$tab.reLaunch('/pages/logo')
						})
					}
				})
			},
			bandAli() {
				let that = this
				// #ifdef APP
				let backUrl = 'https://d.fulewanjia.com/aliLogin.html';
				let aplipayAuthUrl = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm'; //授权地址，可前端写死，也可后端返回
				let appid = '2021004138648121'; //商户的APPID 
				let url = aplipayAuthUrl + '?app_id=' + appid + '&scope=auth_user&redirect_uri=' + backUrl
				url = encodeURIComponent(url);

				plus.runtime.openURL(
					'alipays://platformapi/startapp?appId=20000067&url=' + url, //这里的appId=20000067是固定的，不需要改
					res => {
						//这里写打开URL地址失败后的处理
						uni.showToast({
							title: '请先安装支付宝!',
							icon: "none"
						})
					},
					'com.eg.android.AlipayGphone'
				);
				// #endif
			},
		}
	}
</script>

<style>
	page {
		background-color: #F8F8F8;
	}
</style>

<style lang="scss">

</style>